﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_family_entrance
	/// </summary>
	public partial class oa_family_entrance
	{
		public oa_family_entrance()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("family_id", "oa_family_entrance"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int family_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_family_entrance");
			strSql.Append(" where family_id=@family_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@family_id", MySqlDbType.Int32)
};
			parameters[0].Value = family_id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_family_entrance model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_family_entrance(");
			strSql.Append("person_id,family_no,name,card_id,relationship,telephone)");
			strSql.Append(" values (");
			strSql.Append("@person_id,@family_no,@name,@card_id,@relationship,@telephone)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11),
					new MySqlParameter("@family_no", MySqlDbType.Int32,11),
					new MySqlParameter("@name", MySqlDbType.VarChar,32),
					new MySqlParameter("@card_id", MySqlDbType.VarChar,32),
					new MySqlParameter("@relationship", MySqlDbType.VarChar,32),
					new MySqlParameter("@telephone", MySqlDbType.VarChar,32)};
			parameters[0].Value = model.person_id;
			parameters[1].Value = model.family_no;
			parameters[2].Value = model.name;
			parameters[3].Value = model.card_id;
			parameters[4].Value = model.relationship;
			parameters[5].Value = model.telephone;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_family_entrance model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_family_entrance set ");
			strSql.Append("person_id=@person_id,");
			strSql.Append("family_no=@family_no,");
			strSql.Append("name=@name,");
			strSql.Append("card_id=@card_id,");
			strSql.Append("relationship=@relationship,");
			strSql.Append("telephone=@telephone");
			strSql.Append(" where family_id=@family_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11),
					new MySqlParameter("@family_no", MySqlDbType.Int32,11),
					new MySqlParameter("@name", MySqlDbType.VarChar,32),
					new MySqlParameter("@card_id", MySqlDbType.VarChar,32),
					new MySqlParameter("@relationship", MySqlDbType.VarChar,32),
					new MySqlParameter("@telephone", MySqlDbType.VarChar,32),
					new MySqlParameter("@family_id", MySqlDbType.Int32,11)};
			parameters[0].Value = model.person_id;
			parameters[1].Value = model.family_no;
			parameters[2].Value = model.name;
			parameters[3].Value = model.card_id;
			parameters[4].Value = model.relationship;
			parameters[5].Value = model.telephone;
			parameters[6].Value = model.family_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int family_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_family_entrance ");
			strSql.Append(" where family_id=@family_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@family_id", MySqlDbType.Int32)
};
			parameters[0].Value = family_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string family_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_family_entrance ");
			strSql.Append(" where family_id in ("+family_idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_family_entrance GetModel(int family_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select family_id,person_id,family_no,name,card_id,relationship,telephone from oa_family_entrance ");
			strSql.Append(" where family_id=@family_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@family_id", MySqlDbType.Int32)
};
			parameters[0].Value = family_id;

			becom.Model.oa_family_entrance model=new becom.Model.oa_family_entrance();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["family_id"]!=null && ds.Tables[0].Rows[0]["family_id"].ToString()!="")
				{
					model.family_id=int.Parse(ds.Tables[0].Rows[0]["family_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["person_id"]!=null && ds.Tables[0].Rows[0]["person_id"].ToString()!="")
				{
					model.person_id=int.Parse(ds.Tables[0].Rows[0]["person_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["family_no"]!=null && ds.Tables[0].Rows[0]["family_no"].ToString()!="")
				{
					model.family_no=int.Parse(ds.Tables[0].Rows[0]["family_no"].ToString());
				}
				if(ds.Tables[0].Rows[0]["name"]!=null && ds.Tables[0].Rows[0]["name"].ToString()!="")
				{
					model.name=ds.Tables[0].Rows[0]["name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["card_id"]!=null && ds.Tables[0].Rows[0]["card_id"].ToString()!="")
				{
					model.card_id=ds.Tables[0].Rows[0]["card_id"].ToString();
				}
				if(ds.Tables[0].Rows[0]["relationship"]!=null && ds.Tables[0].Rows[0]["relationship"].ToString()!="")
				{
					model.relationship=ds.Tables[0].Rows[0]["relationship"].ToString();
				}
				if(ds.Tables[0].Rows[0]["telephone"]!=null && ds.Tables[0].Rows[0]["telephone"].ToString()!="")
				{
					model.telephone=ds.Tables[0].Rows[0]["telephone"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select family_id,person_id,family_no,name,card_id,relationship,telephone ");
			strSql.Append(" FROM oa_family_entrance ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_family_entrance";
			parameters[1].Value = "family_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

